package com.company.Lock;

import java.io.IOException;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class CountDemo0 {
    int value = 0;

    public static void main(String[] args) throws IOException, InterruptedException {
        CountDemo0 demo0 = new CountDemo0();
        Lock l = new ReentrantLock();
        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                l.lock();
                demo0.value++;
                l.unlock();
            }
        });

        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                l.lock();
                demo0.value++;
                l.unlock();
            }
        });

        thread1.start();
        thread2.start();

        thread1.join();
        thread2.join();
        System.out.println(demo0.value);
    }
}
